package com.ruoyi.crm.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.crm.domain.vo.CrmProspectProductVo;
import com.ruoyi.crm.domain.bo.CrmProspectProductBo;
import com.ruoyi.crm.service.ICrmProspectProductService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 商机产品表控制器
 * 前端访问路由地址为:/crm/prospectProduct
 *
 * @author ruoyi
 * @date 2025-07-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/prospectProduct")
public class CrmProspectProductController extends BaseController {

    private final ICrmProspectProductService iCrmProspectProductService;

    /**
     * 查询商机产品表列表
     */
    @SaCheckPermission("crm:prospectProduct:list")
    @GetMapping("/list")
    public TableDataInfo<CrmProspectProductVo> list(CrmProspectProductBo bo, PageQuery pageQuery) {
        return iCrmProspectProductService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出商机产品表列表
     */
    @SaCheckPermission("crm:prospectProduct:export")
    @Log(title = "商机产品表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CrmProspectProductBo bo, HttpServletResponse response) {
        List<CrmProspectProductVo> list = iCrmProspectProductService.queryList(bo);
        ExcelUtil.exportExcel(list, "商机产品表", CrmProspectProductVo.class, response);
    }

    /**
     * 获取商机产品表详细信息
     *
     * @param prospectProductId 主键
     */
    @SaCheckPermission("crm:prospectProduct:query")
    @GetMapping("/{prospectProductId}")
    public R<CrmProspectProductVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long prospectProductId) {
        return R.ok(iCrmProspectProductService.queryById(prospectProductId));
    }

    /**
     * 新增商机产品表
     */
    @SaCheckPermission("crm:prospectProduct:add")
    @Log(title = "商机产品表", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CrmProspectProductBo bo) {
        return toAjax(iCrmProspectProductService.insertByBo(bo));
    }

    /**
     * 修改商机产品表
     */
    @SaCheckPermission("crm:prospectProduct:edit")
    @Log(title = "商机产品表", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CrmProspectProductBo bo) {
        return toAjax(iCrmProspectProductService.updateByBo(bo));
    }

    /**
     * 删除商机产品表
     *
     * @param prospectProductIds 主键串
     */
    @SaCheckPermission("crm:prospectProduct:remove")
    @Log(title = "商机产品表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{prospectProductIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] prospectProductIds) {
        return toAjax(iCrmProspectProductService.deleteWithValidByIds(Arrays.asList(prospectProductIds), true));
    }
}
